import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;

@SuppressWarnings("serial")
public class Teisendaja extends JPanel implements ActionListener {

	JPanel meeter, meeter1, meeter2, kiirus, mass, mass1, mass2, temp, binary;
	JTextField meeter_s1, meeter_s2, kiirus_s1, kiirus_s2, mass_s1, mass_s2,
			temp_s1, temp_s2, binary_s1, binary_s2;
	JComboBox meeter_v1, meeter_v2, kiirus_v1, kiirus_v2, mass_v1, mass_v2,
			temp_v1, temp_v2, binary_v1, binary_v2;
	JPanel meeter_2, meeter_3, mass_2, mass_3;
	JLabel vordub, vordub2, vordub3, vordub4, vordub5;
	TitledBorder title, title2, title3, title4, title5;
	JButton arvuta, arvuta2, arvuta3, arvuta4, arvuta5;

	JRadioButton standard, extra, standard2, extra2;
	ButtonGroup grupp, grupp2;

	// meetrite esimene radio
	public void meeter_main(){
		String[] list = {"mm (millimeetrit)", "cm (sentimeetrit)", "m (meetrit)",
				"km (kilomeetrit)", "mi (miili)", "nmi (meremiili)", "ft (jalga)",
				"yd (jardi)", "in (tolli)", "au (astronoomilist ühikut)"};
		meeter_v1.removeAllItems();
		for(int i=0; i<list.length; i++){
			meeter_v1.addItem(list[i]);
		}
		meeter_v1.setSelectedIndex(1);
		
		meeter_v2.removeAllItems();
		for(int i=0; i<list.length; i++){
			meeter_v2.addItem(list[i]);
		}
		meeter_v2.setSelectedIndex(2);
	}
	
	// meetrite teine radio
	public void meeter_radio1(){
		String[] list = {"ym (joktomeeterit)", "zm (zeptomeetrit)", "am (atomeetrit)",
				"fm (femtomeetrit)", "pm (pikomeetrit)", "nm (nanomeeterit)",
				"µm (mikromeeterit)", "mm (millimeetrit)", "cm (sentimeetrit)",
				"dm (detsimeetrit)", "m (meetrit)", "dam (dekameeterit)",
				"hm (hektomeetrit)", "km (kilomeetrit)", "Mm (megameetrit)",
				"Gm (gigameetrit)", "Tm (terameetrit)", "Pm (petameetrit)",
				"Em (eksameetrit)", "Zm (zettameetrit)", "Ym (jottameetrit)"};
		meeter_v1.removeAllItems();
		for(int i=0; i<list.length; i++){
			meeter_v1.addItem(list[i]);
		}
		meeter_v1.setSelectedIndex(8);
	
		meeter_v2.removeAllItems();
		for(int i=0; i<list.length; i++){
			meeter_v2.addItem(list[i]);
		}
		meeter_v2.setSelectedIndex(10);
	}
	// kiiruste esimene radio
	public void kiirus_main(){
		String[] list = {"m/s", "km/h", "mph"};
		kiirus_v1.removeAllItems();
		for(int i=0; i<list.length; i++){
			kiirus_v1.addItem(list[i]);
		}
		kiirus_v1.setSelectedIndex(1);

		kiirus_v2.removeAllItems();
		for(int i=0; i<list.length; i++){
			kiirus_v2.addItem(list[i]);
		}
		kiirus_v2.setSelectedIndex(0);
	}
	
	// masside esimene radio
	public void mass_main(){
		String[] list = {"mg (milligramm)", "g (gramm)", "kg (kilogramm)", "t (tonn)",
				"N (njuuton)", "oz (unts)", "lb (nael)", "st (kivi)"};
		mass_v1.removeAllItems();
		for(int i=0; i<list.length; i++){
			mass_v1.addItem(list[i]);
		}
		mass_v1.setSelectedIndex(1);
		
		mass_v2.removeAllItems();
		for(int i=0; i<list.length; i++){
			mass_v2.addItem(list[i]);
		}
		mass_v2.setSelectedIndex(2);
	}

	// masside teine radio
	public void mass_radio1(){
		String[] list = {"yg (joktogramm)", "zg (zeptogramm)", "ag (atogramm)",
				"fg (femtogramm)", "pg (pikogramm)", "ng (nanogramm)", "µg (mikrogramm)",
				"mg (milligramm)", "cg (sentigramm)", "dg (detsigramm)", "g (gramm)",
				"dag (dekagramm)", "hg (hektogramm)", "kg (kilogramm)", "t (tonn)",
				"Gg (gigagramm)", "Tg (teragramm)", "Pg (petagramm)", "Eg (eksagramm)",
				"Zg (zettagramm)", "Yg (jottagramm)"};
		mass_v1.removeAllItems();
		for(int i=0; i<list.length; i++){
			mass_v1.addItem(list[i]);
		}
		mass_v1.setSelectedIndex(10);
	
		mass_v2.removeAllItems();
		for(int i=0; i<list.length; i++){
			mass_v2.addItem(list[i]);
		}
		mass_v2.setSelectedIndex(13);
	}
		
	// temperatuuride esimene radio
	public void temp_main(){
		String[] list = {"K (Kelvin)", "°C (Celsius)", "°F (Fahrenheit)",
				"°Re (Réaumur)", "°R (Rankine)"};
		temp_v1.removeAllItems();
		for(int i=0; i<list.length; i++){
			temp_v1.addItem(list[i]);
		}
		temp_v1.setSelectedIndex(1);

		temp_v2.removeAllItems();
		for(int i=0; i<list.length; i++){
			temp_v2.addItem(list[i]);
		}
		temp_v2.setSelectedIndex(0);
	}
	
	//binary esimene radio
	public void binary_main(){
		String[] list = {"decimal", "hexademical", "octal", "binary"};
		binary_v1.removeAllItems();
		for(int i=0; i<list.length; i++){
			binary_v1.addItem(list[i]);
		}
		binary_v1.setSelectedIndex(0);
		
		binary_v2.removeAllItems();
		for(int i=0; i<list.length; i++){
			binary_v2.addItem(list[i]);
		}
		binary_v2.setSelectedIndex(1);
	}

	// teisendaja layout
	public Teisendaja() {

		setLayout(new GridLayout(5, 1));

		meeter = new JPanel(new GridLayout(2, 1));

		meeter1 = new JPanel(new FlowLayout());
		meeter_s1 = new JTextField(10);
		meeter_s2 = new JTextField(15);
		meeter_s2.setEditable(false);
		
		meeter_v1 = new JComboBox();
		meeter_v1.addActionListener(this);
		meeter_v2 = new JComboBox();
		meeter_v2.addActionListener(this);
		meeter_main();

		vordub = new JLabel("=");
		arvuta = new JButton("Arvuta");
		arvuta.addActionListener(this);
		meeter1.add(meeter_s1);
		meeter1.add(meeter_v1);
		meeter1.add(vordub);
		meeter1.add(meeter_s2);
		meeter1.add(meeter_v2);
		meeter1.add(arvuta);
		meeter.add(meeter1);

		meeter2 = new JPanel(new FlowLayout());
		standard = new JRadioButton("Ainult tuntumad ühikud");
		standard.setSelected(true);
		standard.addActionListener(this);
		meeter2.add(standard);
		extra = new JRadioButton("Kõik ühikud");
		extra.addActionListener(this);
		meeter2.add(extra);
		meeter.add(meeter2);

		grupp = new ButtonGroup();
		grupp.add(standard);
		grupp.add(extra);

		title = BorderFactory.createTitledBorder("Pikkused");
		meeter.setBorder(title);
		add(meeter);

		kiirus = new JPanel(new FlowLayout());
		kiirus_s1 = new JTextField(15);
		kiirus_s2 = new JTextField(15);
		kiirus_s2.setEditable(false);

		kiirus_v1 = new JComboBox();
		kiirus_v1.addActionListener(this);
		kiirus_v2 = new JComboBox();
		kiirus_v2.addActionListener(this);
		kiirus_main();

		vordub2 = new JLabel("=");
		arvuta2 = new JButton("Arvuta ");
		arvuta2.addActionListener(this);
		kiirus.add(kiirus_s1);
		kiirus.add(kiirus_v1);
		kiirus.add(vordub2);
		kiirus.add(kiirus_s2);
		kiirus.add(kiirus_v2);
		kiirus.add(arvuta2);
		title2 = BorderFactory.createTitledBorder("Kiirused");
		kiirus.setBorder(title2);
		add(kiirus);

		mass = new JPanel(new GridLayout(2, 1));

		mass1 = new JPanel(new FlowLayout());
		mass_s1 = new JTextField(10);
		mass_s2 = new JTextField(15);
		mass_s2.setEditable(false);

		mass_v1 = new JComboBox();
		mass_v1.addActionListener(this);
		mass_v2 = new JComboBox();
		mass_v2.addActionListener(this);
		mass_main();

		vordub3 = new JLabel("=");
		arvuta3 = new JButton(" Arvuta ");
		arvuta3.addActionListener(this);
		mass1.add(mass_s1);
		mass1.add(mass_v1);
		mass1.add(vordub3);
		mass1.add(mass_s2);
		mass1.add(mass_v2);
		mass1.add(arvuta3);
		mass.add(mass1);

		mass2 = new JPanel(new FlowLayout());
		standard2 = new JRadioButton("Ainult tuntumad ühikud ");
		standard2.setSelected(true);
		standard2.addActionListener(this);
		mass2.add(standard2);
		extra2 = new JRadioButton("Kõik ühikud ");
		extra2.addActionListener(this);
		mass2.add(extra2);
		mass.add(mass2);

		grupp2 = new ButtonGroup();
		grupp2.add(standard2);
		grupp2.add(extra2);

		title3 = BorderFactory.createTitledBorder("Massiühikud");
		mass.setBorder(title3);
		add(mass);

		temp = new JPanel(new FlowLayout());
		temp_s1 = new JTextField(15);
		temp_s2 = new JTextField(15);
		temp_s2.setEditable(false);

		temp_v1 = new JComboBox();
		temp_v1.addActionListener(this);
		temp_v2 = new JComboBox();
		temp_v2.addActionListener(this);
		temp_main();

		vordub4 = new JLabel("=");
		arvuta4 = new JButton("Arvuta  ");
		arvuta4.addActionListener(this);
		temp.add(temp_s1);
		temp.add(temp_v1);
		temp.add(vordub4);
		temp.add(temp_s2);
		temp.add(temp_v2);
		temp.add(arvuta4);
		title4 = BorderFactory.createTitledBorder("Temperatuurid");
		temp.setBorder(title4);
		add(temp);
		
		binary = new JPanel(new FlowLayout());
		binary_s1 = new JTextField(15);
		binary_s2 = new JTextField(15);
		binary_s2.setEditable(false);

		binary_v1 = new JComboBox();
		binary_v1.addActionListener(this);
		binary_v2 = new JComboBox();
		binary_v2.addActionListener(this);
		binary_main();

		vordub5 = new JLabel("=");
		arvuta5 = new JButton("  Arvuta  ");
		arvuta5.addActionListener(this);
		binary.add(binary_s1);
		binary.add(binary_v1);
		binary.add(vordub5);
		binary.add(binary_s2);
		binary.add(binary_v2);
		binary.add(arvuta5);
		title5 = BorderFactory.createTitledBorder("Bin-hex-oct-dec");
		binary.setBorder(title5);
		add(binary);

	}

	@Override
	// tegevused ja arvutused
	public void actionPerformed(ActionEvent evt) {
		if (evt.getActionCommand() == "Kõik ühikud") {

			meeter_s1.setText("");
			meeter_s2.setText("");

			meeter_radio1();
		}
		if (evt.getActionCommand() == "Ainult tuntumad ühikud") {

			meeter_s1.setText("");
			meeter_s2.setText("");

			meeter_main();
		}
		if (evt.getActionCommand() == "Kõik ühikud ") {

			mass_s1.setText("");
			mass_s2.setText("");

			mass_radio1();
		}
		if (evt.getActionCommand() == "Ainult tuntumad ühikud ") {

			mass_s1.setText("");
			mass_s2.setText("");

			mass_main();
		}
		if (evt.getActionCommand() == "Arvuta") {
			double sisend, valjund = 0, kordaja = 0;
			int valik, valik2;
			String sisse, valja;
			sisse = meeter_s1.getText();
			try {
				sisend = Double.parseDouble(sisse);
				if (standard.isSelected()) {
					valik = meeter_v1.getSelectedIndex();
					if (valik == 0)
						kordaja = sisend / 1000.;
					if (valik == 1)
						kordaja = sisend / 100.;
					if (valik == 2)
						kordaja = sisend;
					if (valik == 3)
						kordaja = sisend * 1000.;
					if (valik == 4)
						kordaja = sisend * 1609.344; // teen �hikud meetriteks
					if (valik == 5)
						kordaja = sisend * 1852.;
					if (valik == 6)
						kordaja = sisend * 0.3048;
					if (valik == 7)
						kordaja = sisend * 0.9144;
					if (valik == 8)
						kordaja = sisend * 0.0254;
					if (valik == 9)
						kordaja = sisend * 149598000000.;

					valik2 = meeter_v2.getSelectedIndex();
					if (valik2 == 0)
						valjund = kordaja * 1000.;
					if (valik2 == 1)
						valjund = kordaja * 100.;
					if (valik2 == 2)
						valjund = kordaja;
					if (valik2 == 3)
						valjund = kordaja / 1000.;
					if (valik2 == 4){
						if (valik == 4){
							valjund = kordaja / 1609.344; // kui valitud on samad, siis jagab tagasi, et vastus oleks 1
						}else{
							valjund = kordaja * 0.000621371192; // teeb meetrid antud �hikuks
						}
					}
					if (valik2 == 5){
						if (valik == 5){
							valjund = kordaja / 1852.;
						}else{
							valjund = kordaja * 0.000539956803;
						}
					}
					if (valik2 == 6){
						if (valik == 6){
							valjund = kordaja / 0.3048;
						}else{
							valjund = kordaja * 3.2808399;
						}
					}
					if (valik2 == 7){
						if (valik == 7){
							valjund = kordaja / 0.9144;
						}else{
							valjund = kordaja * 1.0936133;
						}
					}
					if (valik2 == 8){
						if (valik == 8){
							valjund = kordaja / 0.0254;
						}else{
							valjund = kordaja * 39.3700787;
						}
					}
					if (valik2 == 9){
						if (valik == 9){
							valjund = kordaja / 149598000000.;
						}else{
							valjund = kordaja * 0.00000000000668458134;
						}
					}
				}
				if (extra.isSelected()) {
					valik = meeter_v1.getSelectedIndex();
					if (valik == 0)
						kordaja = sisend * 0.000000000000000000000001;
					if (valik == 1)
						kordaja = sisend * 0.000000000000000000001;
					if (valik == 2)
						kordaja = sisend * 0.000000000000000001;
					if (valik == 3)
						kordaja = sisend * 0.000000000000001;
					if (valik == 4)
						kordaja = sisend * 0.000000000001;
					if (valik == 5)
						kordaja = sisend * 0.000000001;
					if (valik == 6)
						kordaja = sisend * 0.000001;
					if (valik == 7)
						kordaja = sisend * 0.001;
					if (valik == 8)
						kordaja = sisend * 0.01;
					if (valik == 9)
						kordaja = sisend * 0.1;
					if (valik == 10)
						kordaja = sisend;
					if (valik == 11)
						kordaja = sisend * 10.;
					if (valik == 12)
						kordaja = sisend * 100.;
					if (valik == 13)
						kordaja = sisend * 1000.;
					if (valik == 14)
						kordaja = sisend * 1000000.;
					if (valik == 15)
						kordaja = sisend * 1000000000.;
					if (valik == 16)
						kordaja = sisend * 1000000000000.;
					if (valik == 17)
						kordaja = sisend * 1000000000000000.;
					if (valik == 18)
						kordaja = sisend * 1000000000000000000.;
					if (valik == 19)
						kordaja = sisend * 1000000000000000000000.;
					if (valik == 20)
						kordaja = sisend * 1000000000000000000000000.;

					valik2 = meeter_v2.getSelectedIndex();
					if (valik2 == 0)
						valjund = kordaja / 0.000000000000000000000001;
					if (valik2 == 1)
						valjund = kordaja / 0.000000000000000000001;
					if (valik2 == 2)
						valjund = kordaja / 0.000000000000000001;
					if (valik2 == 3)
						valjund = kordaja / 0.000000000000001;
					if (valik2 == 4)
						valjund = kordaja / 0.000000000001;
					if (valik2 == 5)
						valjund = kordaja / 0.000000001;
					if (valik2 == 6)
						valjund = kordaja / 0.000001;
					if (valik2 == 7)
						valjund = kordaja / 0.001;
					if (valik2 == 8)
						valjund = kordaja / 0.01;
					if (valik2 == 9)
						valjund = kordaja / 0.1;
					if (valik2 == 10)
						valjund = kordaja;
					if (valik2 == 11)
						valjund = kordaja / 10.;
					if (valik2 == 12)
						valjund = kordaja / 100.;
					if (valik2 == 13)
						valjund = kordaja / 1000.;
					if (valik2 == 14)
						valjund = kordaja / 1000000.;
					if (valik2 == 15)
						valjund = kordaja / 1000000000.;
					if (valik2 == 16)
						valjund = kordaja / 1000000000000.;
					if (valik2 == 17)
						valjund = kordaja / 1000000000000000.;
					if (valik2 == 18)
						valjund = kordaja / 1000000000000000000.;
					if (valik2 == 19)
						valjund = kordaja / 1000000000000000000000.;
					if (valik2 == 20)
						valjund = kordaja / 1000000000000000000000000.;
				}
				valja = String.valueOf(valjund);
				meeter_s2.setText(valja);
			} catch (Exception e) {
				meeter_s2.setText("*Vigane sisend*");
			}

		}
		if (evt.getActionCommand() == " Arvuta ") {
			double sisend3, valjund3 = 0, kordaja3 = 0;
			int valik3, valik33;
			String sisse3, valja3;
			sisse3 = mass_s1.getText();
			try {
				sisend3 = Double.parseDouble(sisse3);
				if (standard2.isSelected()) {
					valik3 = mass_v1.getSelectedIndex();
					if (valik3 == 0)
						kordaja3 = sisend3 / 1000.;
					if (valik3 == 1)
						kordaja3 = sisend3;
					if (valik3 == 2)
						kordaja3 = sisend3 * 1000;
					if (valik3 == 3)
						kordaja3 = sisend3 * 1000000.;
					if (valik3 == 4)
						kordaja3 = sisend3 * 102;
					if (valik3 == 5)
						kordaja3 = sisend3 * 28.3495231;
					if (valik3 == 6)
						kordaja3 = sisend3 * 453.59237;
					if (valik3 == 7)
						kordaja3 = sisend3 * 6350.29318;

					valik33 = mass_v2.getSelectedIndex();
					if (valik33 == 0)
						valjund3 = kordaja3 * 1000.;
					if (valik33 == 1)
						valjund3 = kordaja3;
					if (valik33 == 2)
						valjund3 = kordaja3 / 1000;
					if (valik33 == 3)
						valjund3 = kordaja3 / 1000000.;
					if (valik33 == 4){
						if (valik3 == 4){
							valjund3 = kordaja3 / 102;
						}else{
							valjund3 = kordaja3 * 0.00980665;
						}
					}
					if (valik33 == 5){
						if (valik3 == 5){
							valjund3 = kordaja3 / 28.3495231;
						}else{
							valjund3 = kordaja3 * 0.0352739619;
						}
					}
					if (valik33 == 6){
						if (valik3 == 6){
							valjund3 = kordaja3 / 6350.29318;
						}else{
							valjund3 = kordaja3 * 0.0022046226218488;
						}
					}
					if (valik33 == 7){
						if (valik3 == 7){
							valjund3 = kordaja3 / 453.59237;
						}else{
							valjund3 = kordaja3 * 0.0001574730444177697;
						}
					}
				}
				if (extra2.isSelected()) {
					valik3 = mass_v1.getSelectedIndex();
					if (valik3 == 0)
						kordaja3 = sisend3 * 0.000000000000000000000001;
					if (valik3 == 1)
						kordaja3 = sisend3 * 0.000000000000000000001;
					if (valik3 == 2)
						kordaja3 = sisend3 * 0.000000000000000001;
					if (valik3 == 3)
						kordaja3 = sisend3 * 0.000000000000001;
					if (valik3 == 4)
						kordaja3 = sisend3 * 0.000000000001;
					if (valik3 == 5)
						kordaja3 = sisend3 * 0.000000001;
					if (valik3 == 6)
						kordaja3 = sisend3 * 0.000001;
					if (valik3 == 7)
						kordaja3 = sisend3 * 0.001;
					if (valik3 == 8)
						kordaja3 = sisend3 * 0.01;
					if (valik3 == 9)
						kordaja3 = sisend3 * 0.1;
					if (valik3 == 10)
						kordaja3 = sisend3;
					if (valik3 == 11)
						kordaja3 = sisend3 * 10.;
					if (valik3 == 12)
						kordaja3 = sisend3 * 100.;
					if (valik3 == 13)
						kordaja3 = sisend3 * 1000.;
					if (valik3 == 14)
						kordaja3 = sisend3 * 1000000.;
					if (valik3 == 15)
						kordaja3 = sisend3 * 1000000000.;
					if (valik3 == 16)
						kordaja3 = sisend3 * 1000000000000.;
					if (valik3 == 17)
						kordaja3 = sisend3 * 1000000000000000.;
					if (valik3 == 18)
						kordaja3 = sisend3 * 1000000000000000000.;
					if (valik3 == 19)
						kordaja3 = sisend3 * 1000000000000000000000.;
					if (valik3 == 20)
						kordaja3 = sisend3 * 1000000000000000000000000.;

					valik33 = mass_v2.getSelectedIndex();
					if (valik33 == 0)
						valjund3 = kordaja3 / 0.000000000000000000000001;
					if (valik33 == 1)
						valjund3 = kordaja3 / 0.000000000000000000001;
					if (valik33 == 2)
						valjund3 = kordaja3 / 0.000000000000000001;
					if (valik33 == 3)
						valjund3 = kordaja3 / 0.000000000000001;
					if (valik33 == 4)
						valjund3 = kordaja3 / 0.000000000001;
					if (valik33 == 5)
						valjund3 = kordaja3 / 0.000000001;
					if (valik33 == 6)
						valjund3 = kordaja3 / 0.000001;
					if (valik33 == 7)
						valjund3 = kordaja3 / 0.001;
					if (valik33 == 8)
						valjund3 = kordaja3 / 0.01;
					if (valik33 == 9)
						valjund3 = kordaja3 / 0.1;
					if (valik33 == 10)
						valjund3 = kordaja3;
					if (valik33 == 11)
						valjund3 = kordaja3 / 10.;
					if (valik33 == 12)
						valjund3 = kordaja3 / 100.;
					if (valik33 == 13)
						valjund3 = kordaja3 / 1000.;
					if (valik33 == 14)
						valjund3 = kordaja3 / 1000000.;
					if (valik33 == 15)
						valjund3 = kordaja3 / 1000000000.;
					if (valik33 == 16)
						valjund3 = kordaja3 / 1000000000000.;
					if (valik33 == 17)
						valjund3 = kordaja3 / 1000000000000000.;
					if (valik33 == 18)
						valjund3 = kordaja3 / 1000000000000000000.;
					if (valik33 == 19)
						valjund3 = kordaja3 / 1000000000000000000000.;
					if (valik33 == 20)
						valjund3 = kordaja3 / 1000000000000000000000000.;
				}
				valja3 = String.valueOf(valjund3);
				mass_s2.setText(valja3);
			} catch (Exception e) {
				mass_s2.setText("*Vigane sisend*");
			}
		}
		if (evt.getActionCommand() == "Arvuta ") {
			String sisse2, v2lja2;
			double sisend2, v2ljund2 = 0, vahetulemus = 0;
			int valik21, valik22;
			sisse2 = kiirus_s1.getText();
			try {
				sisend2 = Double.parseDouble(sisse2);
				valik21 = kiirus_v1.getSelectedIndex();
				if (valik21 == 0)
					vahetulemus = sisend2;
				if (valik21 == 1)
					vahetulemus = sisend2 / 3.6;
				if (valik21 == 2)
					vahetulemus = sisend2 / 2.2369;

				valik22 = kiirus_v2.getSelectedIndex();
				if (valik22 == 0)
					v2ljund2 = vahetulemus;
				if (valik22 == 1)
					v2ljund2 = vahetulemus * 3.6;
				if (valik22 == 2)
					v2ljund2 = vahetulemus * 2.2368;

				v2lja2 = String.valueOf(v2ljund2);
				kiirus_s2.setText(v2lja2);

			} catch (Exception e) {
				kiirus_s2.setText("*Vigane sisend*");
			}
		}
		if (evt.getActionCommand() == "Arvuta  ") {
			String sisse4, v2lja4;
			double sisend4, v2ljund4 = 0, vahetulemus4 = 0;
			int valik4, valik44;
			sisse4 = temp_s1.getText();
			try {
				sisend4 = Double.parseDouble(sisse4);
				valik4 = temp_v1.getSelectedIndex();
				if (valik4 == 0) {
					if (sisend4 < 0) {
						vahetulemus4 = -273.15;
						temp_s1.setText("0");
					} else {
						vahetulemus4 = sisend4 - 273.15;
					}
				}
				if (valik4 == 1) {
					if (sisend4 < -273.15) {
						vahetulemus4 = -273.15;
						temp_s1.setText("-273.15");
					} else {
						vahetulemus4 = sisend4;
					}
				}
				if (valik4 == 2) {
					if (sisend4 < -459.67) {
						vahetulemus4 = -273.15;
						temp_s1.setText("-459.67");
					} else {
						vahetulemus4 = (sisend4 - 32) * 5 / 9;
					}
				}
				if (valik4 == 3){
					if(sisend4<-218.52){
						sisend4 = -218.52;
						temp_s1.setText("-218.52");
					}
					vahetulemus4 = sisend4 * 1.25;
				}
				if (valik4 == 4){
					if(sisend4<0){
						sisend4 = 0;
						temp_s1.setText("0");
					}
					vahetulemus4 = (sisend4 - 491.67) * 5/9;
				}

				valik44 = temp_v2.getSelectedIndex();
				if (valik44 == 0)
					v2ljund4 = vahetulemus4 + 273.15;
				if (valik44 == 1)
					v2ljund4 = vahetulemus4;
				if (valik44 == 2)
					v2ljund4 = vahetulemus4 * 9 / 5 + 32;
				if (valik44 == 3){
					if (valik4 == 3){
						v2ljund4 = vahetulemus4 / 1.25;
					}else{
						v2ljund4 = vahetulemus4 * 0.8;
					}
				}
				if (valik44 == 4){
					if (valik4 == 4){
						v2ljund4 = sisend4;
					}else{
						v2ljund4 = (vahetulemus4 + 273.15) * 9/5;
					}
				}

				v2lja4 = String.valueOf(v2ljund4);
				temp_s2.setText(v2lja4);

			} catch (Exception e) {
				temp_s2.setText("*Vigane sisend*");
			}
		}
		// "decimal", "hexademical", "octal", "binary"
		if (evt.getActionCommand() == "  Arvuta  ") {
			String sisse2, v2ljund2 = "";
			int valik51, valik52, vahetulemus = 0;
			sisse2 = binary_s1.getText();
			try {
				valik51 = binary_v1.getSelectedIndex();
				if (valik51 == 0)
					vahetulemus = Integer.parseInt(sisse2);
				if (valik51 == 1)
					vahetulemus = Integer.parseInt(sisse2,16);
				if (valik51 == 2)
					vahetulemus = Integer.parseInt(sisse2,8);
				if (valik51 == 3)
					vahetulemus = Integer.parseInt(sisse2,2);
				
				valik52 = binary_v2.getSelectedIndex();
				if (valik52 == 0)
					v2ljund2 = vahetulemus+"";
				if (valik52 == 1)
					v2ljund2 = Integer.toHexString(vahetulemus);
				if (valik52 == 2)
					v2ljund2 = Integer.toOctalString(vahetulemus);
				if (valik52 == 3)
					v2ljund2 = Integer.toBinaryString(vahetulemus);

				binary_s2.setText(v2ljund2);
			} catch (Exception e) {
				binary_s2.setText("*Vigane sisend*");
			}
		}
	}
}